﻿namespace Er.Shared.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using AutoMapper;

    using Models;

    internal class WordViewModelRepository : IWordViewModelRepository
    {
        private readonly IWordRepository _wordRepository;

        private readonly IWordViewModelFactory _wordViewModelFactory;

        public WordViewModelRepository(IWordRepository wordRepository, IWordViewModelFactory wordViewModelFactory)
        {
            _wordRepository = wordRepository;
            _wordViewModelFactory = wordViewModelFactory;
        }

        public IEnumerable<IWordViewModel> GetWords()
        {
            var words = _wordRepository.GetWords();
            var wvms = words.Select(
                x =>
                    {
                        var wvm = _wordViewModelFactory.Create();
                        wvm.Id = x.WordId;
                        wvm.Spell = x.WordSpell;
                        return wvm;
                    });
            return wvms;
        }

        public void Add(IWordViewModel word)
        {
            _wordRepository.Add(new Word() { WordId = Guid.NewGuid(), WordSpell = word.Spell });
        }

        public void Save()
        {
            //_wordRepository.s
        }
    }
}